import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import styleImport, { VantResolve } from 'vite-plugin-style-import';

import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()]
		}),
		Components({
			resolvers: [ElementPlusResolver()]
		})
	],
	server: {
		open: true,
		port: 8888,
		proxy: {
			'/api': {
				target: 'http://localhost:3000', //实际请求地址
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api/, '')
			}
		}
	},
	resolve: {
		alias: [
			{
				find: '@',
				replacement: resolve(__dirname, './src')
			}
		]
	},
	css: {
		preprocessorOptions: {
			less: {
				// modifyVars: {
				// 	hack: `true; @import (reference) "${resolve('src/assets/less/index.less')}";`
				// },
				javascriptEnabled: true,
				globalVars: {
					// 全局变量
					mainColor: 'red'
				}
			}
		}
	}
});
